package com.unitd.modules.sso.controller;

import com.unitd.frame.comm.tree.Menu;
import com.unitd.modules.comm.web.BaseController;
import com.unitd.modules.sso.util.SecurityUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @desc 系统菜单信息管理前端控制器
 * @filename SysMenuController.java
 * @copyright www.unitd.com
 * @version 1.0
 * @author Hudan
 * @date 2018/1/31
 */
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController extends BaseController {

	/**
	 * @desc 获取系统菜单树状结构数据
	 * @param param 请求参数
	 * @return String
	 */
	@RequestMapping(value = "getTreeData", method = RequestMethod.GET)
	public List<Menu> getTreeData(@RequestParam Map<String, Object> param) {
		// 按照层级关系进行排序的树状结构菜单列表
		List<Menu> baseMenus = new ArrayList<>();
		Menu menu;
		if (SecurityUtil.isSuperAdmin()) {
			menu = new Menu("全局管理", "fa-cubes", true);
			menu.getChildren().add(new Menu("环境管理", "&#xe61d;", "profile/list.html"));
			menu.getChildren().add(new Menu("用户管理", "&#xe612;", "user/list.html"));
			baseMenus.add(menu);
		}

		menu = new Menu("配置管理", "fa-cubes", !SecurityUtil.isSuperAdmin());
		menu.getChildren().add(new Menu("应用管理", "&#xe63b;", "app/list.html"));
		menu.getChildren().add(new Menu("配置管理", "&#xe609;", "config/list.html"));
		menu.getChildren().add(new Menu("加密工具", "&#xe64e;", "config/encrypt.html"));
		baseMenus.add(menu);

		menu = new Menu("监控管理", "fa-cubes", true);
		menu.getChildren().add(new Menu("接入应用节点", "&#xe64e;", "monitor/app.html"));
		baseMenus.add(menu);
		return baseMenus;
	}
}